#!/usr/bin/env python
# coding:utf-8
'''
主机自动巡检
'''
import paramiko
import re
import time
import os
import sys
#


# def Auto_Lnspection(ip_dress, port_dress,root_dress,password_dress):
#     # 建立连接
#     ssh = paramiko.SSHClient()
#     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
#     ssh.connect(ip_dress, port_dress, root_dress, password_dress)
#     stdin, stdout, stderr = ssh.exec_command("df")
#     date1 = stdout.readlines()
#     for i in date1:
#         print(i)
#     ssh.close()

#
# Auto_Lnspection("192.168.20.210",22,"root","root")
#paramiko ，用于普通的linux系统，可用于windows
class paramikossh:
    def __init__(self,ip,user,password,port=22):
        self.ip = ip
        self.user = user
        self.password = password
        self.port = port
        self.ssh = paramiko.SSHClient()
    def login(self):
        try:
            self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            print(self.ip,self.password,self.port,self.password)
            self.ssh.connect(self.ip, self.port,self.user,self.password)
            print(self.ssh)
            return True
        except Exception as e:
            print(e)
            return False
    def command(self,cmd):
        stdin,stdout,stderr = self.ssh.exec_command(cmd)
        date1 = stdout.readlines()
        return date1
    def logout(self):
        self.ssh.close()

a = paramikossh("10.180.169.202","admin","Jmo@CId$")
print(a.login())
for i in a.command("df"):
    print(i)
